package com.swagger.doc.swaggertodoc.service.impl;

import com.swagger.doc.swaggertodoc.dao.PersonRepository;
import com.swagger.doc.swaggertodoc.req.Person;
import com.swagger.doc.swaggertodoc.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;


@Service
public class PersonServiceImpl implements PersonService {

    @Autowired
    private PersonRepository personRepository;


    @Override
    public Optional<Person> findById(String id) {
        //CrudRepository中的方法
        return personRepository.findById(id);
    }

    @Override
    public Person save(Person blog) {
        return personRepository.save(blog);
    }

    @Override
    public void delete(Person blog) {
        personRepository.delete(blog);
    }

    @Override
    public Optional<Person> findOne(String id) {
        return personRepository.findById(id);
    }

    @Override
    public List<Person> findAll() {
        return (List<Person>) personRepository.findAll();
    }

    @Override
    public Page<Person> findByAuthor(String author, PageRequest pageRequest) {
        return personRepository.findByAuthor(author, pageRequest);
    }

    @Override
    public Page<Person> findByTitle(String title, PageRequest pageRequest) {
        return personRepository.findByTitle(title, pageRequest);
    }
}

